package com.teama4.shop.controller;

import com.teama4.shop.domain.User;
import com.teama4.shop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/Merchant")
public class MerchantController {
    @Autowired
    private UserService userService;

    @GetMapping("")
    public String merchant() {
        return "/merchant/index";
    }

    @PostMapping("/first")
    public String first(int id, String password, Model model){
        User user = new User();
        user.setId(id);
        user.setPassword(password);
        if(userService.findUser(user)==1) {
            user = userService.selectByPrimaryKey(id);
            model.addAttribute("user", user);
            return "/merchant/merchant-home-page";
        } else {
            return "/common/404";
        }
    }
}
